﻿using System;
using System.Data;
using System.Web.Script.Services;
using System.Web.Services;
using DataAccessObject;
using EntityObject;
using Newtonsoft.Json;
using ThangNM_LIB.FUNC;

namespace API
{
    /// <summary>
    /// Summary description for OSM
    /// </summary>
    [WebService(Namespace = "http://ecustoms.customs.gov.vn/", Description = "Hải quan Việt Nam (http://www.customs.gov.vn/) - Open Street Map (http://www.openstreetmap.org/) - Leaflet (http://leafletjs.com/)")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    
    [System.Web.Script.Services.ScriptService]
    public class OSM : System.Web.Services.WebService
    {
        [WebMethod(Description = "get list ECustoms", EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public String getList_ECustoms()
        {
            DataTable dt = (new ECustomsDAO()).SelectList();
            if (dt != null && dt.Rows.Count > 0)
            {
                return JsonConvert.SerializeObject(dt);
            }
            return null;
        }

        [WebMethod(Description = "get list FeatureGroup", EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public String getList_FeatureGroup()
        {
            DataTable dt = (new FeatureGroupDAO()).SelectList();
            if (dt != null && dt.Rows.Count > 0)
            {
                return JsonConvert.SerializeObject(dt);
            }
            return null;
        }

        [WebMethod(Description = "get GeoJSON FeatureGroup by PK_iFGID", EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public String getGeoJSON_FeatureGroup_ByPK_iFGID(Int32 PK_iFGID)
        {
            FeatureGroupEO obj = new FeatureGroupEO();
            obj.PK_iFGID = PK_iFGID;
            obj = (new FeatureGroupDAO()).SelectItem(obj);
            if (obj != null)
            {
                return obj.sGeoJSON;
            }
            return "";
        }

        [WebMethod(Description = "set GeoJSON FeatureGroup", EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public Boolean setGeoJSON_FeatureGroup(String sFeatureGroup, String sGeoJSON)
        {
            FeatureGroupEO obj = new FeatureGroupEO(0, sFeatureGroup, sGeoJSON, true);
            return (new FeatureGroupDAO()).Insert_Update_Delete(obj, ConstEx.Insert_Update_Delete.Insert);
        }
    }
}
